import socket

client = socket.socket()

client.connect(('localhost', 6969))


while True:
    send_text = input('>>>: ')
    if not send_text:
        continue
    if send_text == 'exit':
        client.send(send_text.encode())
        break
    client.send(send_text.encode())
    total_size = int(client.recv(1024).decode())
    print('receive total size: ', total_size)
    client.send('ready to receive data'.encode())
    receive_size = 0
    while receive_size < total_size:
        if total_size - receive_size > 1024:
            size = 1024
        else:
            size = total_size - receive_size
        receive_size += size
        data = client.recv(size)
    else:
        print('received size: ', receive_size)
        print(data.decode())

client.close()
